package convertdate01;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * JDK1.8 对日期对象和日期字符串相互转换
 * 1.将日期对象转换为日期字符串
 *   DateTimeFormatter类:
 *    static DateTimeFormatter ofPattern(String pattern)
 *    String format(TemporalAccessor temporal)
 */
public class ConvertDateDemo02 {
    public static void main(String[] args) {
        method01();
    }

    private static void method01() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);    //2024-04-19T23:38:20.289932

        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(df.format(now));  //  2024-04-19 23:38:20
    }
}
